import axios from 'axios'
import Qs from 'qs'
import { Toast } from 'vant'; 

export const baseURL='http://meeting.goboosoft.com/';


 const service = axios.create({
    baseURL: baseURL,
    timeout: 0,  
})

// const service = axios.create({
//     baseURL: baseURLShare,
//     timeout: 0,
    
// })
service.interceptors.request.use(config => {
    config.headers={ 
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
   }
  
    
    return config
}, (error) => {
    console.warn("request.error")
    return errorHandler(error)
})




service.interceptors.response.use((res) => {

    return res
}, (error) => {
    console.warn("response.error")
    return errorHandler(error)
})

// GET 请求
export function get(url, params , headers = {}) {

 

    return service.get(url,{
        params,
        headers
    }).then((res) => {
        // Toast.clear();
        // console.log("res",res.data)
        if(res.data.code!=200){
            Toast({ message: res.data.msg, position: "bottom" });
        }
        return Promise.resolve(res.data)
    }).catch((err) => {
        Toast.clear();
        Toast({ message: "网络连接失败", position: "bottom" });
        return Promise.errorHandler(err)
    })
}
// POST 请求
export function post(url,  params, headers = {}){
 

 
    return service.post(url,Qs.stringify(params)  , {
        headers
    }).then((res) => {
        // Toast.clear();
       console.log(url,res.data)
        if(res.data.code!=200){
            Toast({ message: res.data.msg, position: "bottom" });
        }
        return Promise.resolve(res.data)
    }).catch((err) => {
        Toast.clear();
        Toast({ message: "网络连接失败", position: "bottom" });
        return Promise.errorHandler(err)
    })
} 
const errorHandler=(err)=>{
    console.log("err",err) 
}


export const _API = {
    // selectShopByid:"haha"
    homeOopinion: query => post('user/home/opinion', query),  //意见反馈提交

    userCzlog: query => post('user/user/czlog', query),  //充值中心 充值记录

    userUserCoupons: query => get('user/user/usercoupons', query),  //我的优惠券列表

    userPay: query => post('user/user/pay', query),  //充值操作

    userRecharge: query => get('user/home/recharge', query),  //充值面额列表
   
    userMember: query => post('user/user/member', query),  //获取个人信息

    userReceive_coupons: query => post('user/user/receive_coupons', query),  //会员领取优惠券

    userHomeCoupons: query => get('user/home/coupons', query),  //优惠券列表）（公共）

    userUserYelog: query => get('user/user/yelog', query),  //余额记录
    
   
    userConfig: query => post('user/user/config', query),  //微信配置

    userWrite: query => post('user/write', query),  //微信配置

    userWriteHx: query => post('user/write/hx', query),   //核销提交



    userWriteHxOrder: query => get('user/write/hxOrder', query),   //核销订单列表

    userUserPayOrder: query => get('user/user/payOrder', query),   //用户订单列表

    userUserOrderpay: query => post('user/user/orderpay', query),   //待付款提交

    userUserJflog: query => post('user/user/jflog', query),   //积分记录

    userWriteYplog: query => post('user/write/yplog', query),   //核销员 饮品订单

    userUserOrder_cancel: query => post('user/user/order_cancel', query),   //取消订单
   
   

  }


 